// 全局请求封装
const base_url = 'http://www.lihyweb.cn/api'
 
// 需要修改token，和根据实际修改请求头
export default (url, method,type = '',params = {}) => {
	// 获取本地token
	// const token = uni.getStorageSync('GetPhone_Token');
	// 根据请求方法或URL来判断是否添加请求头
	let header = {}
	if(type == 'file'){
		header['content-type'] = "application/multipart/form-data"
	} else if (type == 'form'){
		header['content-type'] = "application/x-www-form-urlencoded"
	} else {
		header['content-type'] = "application/json"
	}
	return new Promise((resolve, reject) => {
		uni.request({
			url: base_url + url,
			method: method,
			header: header,
			data: params,
			success(response) {
				const res = response.data
				if (res.code == 200) {
					resolve(res);
				} else {
					uni.showToast({
						title: res.message,
						icon:'error',
						mask:true,
						duration: 1500
					});
					resolve(res);
				}
			},
			fail(err) {
				reject(err);
				console.log(err)
			},
			complete() {
 
			}
		});
	}).catch((e) => {});
};